<?php 
if ( function_exists( 'add_theme_support' ) ) {
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 93, 74 ); // default Post Thumbnail dimensions (cropped)

	// additional image sizes
	// delete the next line if you do not need additional image sizes
	add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)
}

/* Registrar menu */
function register_my_menus() {
	register_nav_menus(
	array( 'main-menu' => __( 'Main Menu' ),
	       'footer-menu' => __( 'Footer Menu' ) 
	     )
	);
}
add_action( 'init', 'register_my_menus' );

/* Cria espaços verticas entre os blocos do layout */
function do_vertical_space ($value) {
	echo '<div style="height:' . $value .'px"></div>';
}

/* Cria espaços horizontal entre os blocos do layout */
function do_horizontal_space ($value) {
	echo '<div style="width:' . $value .'px"></div>';
}


/* Registra o sidebar */ 
if ( function_exists( 'register_sidebars' ) );
register_sidebar( array('name'=> 'Lateral Direita Home',) );
register_sidebar( array('name'=> 'Lateral Direita Noticias',) );


/* Inclui os widgt de publicidade */
include_once 'avespt-widget/publicidade.php';
include_once 'avespt-widget/media-social.php';

/* Registar o widget quando carrega no CORE */
add_action('widgets_init', just_register_widgets);


function just_register_widgets() {
	register_widget('Pub300x94x1');
	register_widget('Pub300x94x2');
	register_widget('Pub300x94x3');
	register_widget('Pub4x145x145');
	register_widget('PubAdsense300x250');
	register_widget('PubAdsense300x600');
	register_widget('MedSocFace300x250');
}


function the_breadcrumb() {
	if (!is_home()) {
		echo '<a href="';
		echo get_option('home');
		echo '">';
		bloginfo('name');
		echo "</a> » ";
		if (is_category() || is_single()) {
			the_category('title_li=');
			if (is_single()) {
				echo " » ";
				the_title();
			}
		} elseif (is_page()) {
			echo the_title();
		}
	}
}

function pagination( $query, $baseURL = '' ) {
	if ( ! $baseURL ) $baseURL = get_bloginfo( 'url' );
	$page = $query->query_vars["paged"];
	if ( !$page ) $page = 1;
	$qs = $_SERVER["QUERY_STRING"] ? "?".$_SERVER["QUERY_STRING"] : "";
	// Only necessary if there's more posts than posts-per-page
	if ( $query->found_posts > $query->query_vars["posts_per_page"] ) {
		echo '<ul class="paging">';
		// Previous link?
		if ( $page > 1 ) {
			echo '<li class="previous"><a href="'.$baseURL.'page/'.($page-1).'/'.$qs.'">« Anterior</a></li>';
		}
		// Loop through pages
		for ( $i=1; $i <= $query->max_num_pages; $i++ ) {
			// Current page or linked page?
			if ( $i == $page ) {
				echo '<li class="active">'.$i.'</li>';
			} else {
				echo '<li><a href="'.$baseURL.'page/'.$i.'/'.$qs.'">'.$i.'</a></li>';
			}
		}
		// Next link?
		if ( $page < $query->max_num_pages ) {
			echo '<li><a href="'.$baseURL.'page/'.($page+1).'/'.$qs.'">Próximo »</a></li>';
		}
		echo '</ul>';
	}
}


/**
 * Get either a Gravatar URL or complete image tag for a specified email address.
 *
 * @param string $email The email address
 * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
 * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
 * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
 * @param boole $img True to return a complete IMG tag False for just the URL
 * @param array $atts Optional, additional key/value attributes to include in the IMG tag
 * @return String containing either just a URL or a complete image tag
 * @source http://gravatar.com/site/implement/images/php/
 */
function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
	$url = 'http://www.gravatar.com/avatar/';
	$url .= md5( strtolower( trim( $email ) ) );
	$url .= "?s=$s&d=$d&r=$r";
	if ( $img ) {
		$url = '<img src="' . $url . '"';
		foreach ( $atts as $key => $val )
			$url .= ' ' . $key . '="' . $val . '"';
		$url .= ' />';
	}
	return $url;
}





/*
 * Retorna a url atual
*/
function url_atual(){
	$dominio= $_SERVER['HTTP_HOST'];
	$url = "http://" . $dominio. $_SERVER['REQUEST_URI'];
	return $url;
}

function conteudo_barra_page ($titulo) { ?>
	<div style="margin: 25px auto; width: 470px; float: left;">
		<span style="<?php fonte_cor('cinza18') ?>"><?php echo $titulo; ?></span>
		<span style="<?php fonte_cor('azul14') ?>"><a href="<?php echo url_atual(); ?>"><?php echo url_atual(); ?></a></span>
	</div>
	<div style="margin: 25px auto; width: 325px; float: left;"><?php load_shared ();?></div>
	<div style="margin: 18px auto; width: 72px; float: right;">
		<img alt="" src="<?php echo bloginfo('template_directory')?>/images/icon/impressora-128x128.png" width="32" height="32">
		<img alt="" src="<?php echo bloginfo('template_directory')?>/images/icon/pdficon-32x32.png" width="32" height="32">
	</div>
<?php 	
}

function titulo_barra_page ($titulo, $pagina) { ?>
	<div style="margin: 18px auto; width: 370px; float: left;"><span style="<?php fonte_cor('preto30') ?>"><?php echo $titulo;?></span></div>
	<div style="margin: auto; width: 580px; height: 65px; float: right; background-color: #0091c4;">
		<div style="margin: 18px 0 0 18px;"><span style="<?php fonte_cor('branco28');?>"><?php echo $pagina;?></span></div>
	</div>	
<?php 
}

function direito_barra_page ($texto, $pag_name) { ?>
	<div style="margin-top: 15px;">
	<span style="<?php fonte_cor('cinza16') ?>">
	<?php echo $texto.': '.$pag_name;?> &copy; Todos os direitos reservados
	</span>
	</div>
<?php 	
}





add_filter('user_contactmethods', 'extra_contact_info');
function extra_contact_info($contactmethods) {
	//Retira itens do formulário
	unset($contactmethods['aim']);
	unset($contactmethods['yim']);
	unset($contactmethods['jabber']);
	//Acresce itens no formulário
	$contactmethods['telefone'] 	 = 'Telefone';
	$contactmethods['fax'] 			 = 'Fax';
	$contactmethods['morada'] 		 = 'Morada';
	$contactmethods['codigo_postal'] = 'Código postal';
	$contactmethods['concelho'] 	 = 'Concelho';
	$contactmethods['localidade'] 	 = 'Localidade';
	$contactmethods['stam'] 	  	 = 'STAM';
	$contactmethods['especies'] 	 = 'Espécies que cria';
	$contactmethods['clube'] 		 = 'Clube';
	$contactmethods['clube2'] 		 = 'Clube';
	$contactmethods['clube3'] 		 = 'Clube';
	$contactmethods['modalidade']    = 'Modalidade';
	$contactmethods['modalidade2'] 	 = 'Modalidade';
	$contactmethods['modalidade3'] 	 = 'Modalidade';
	$contactmethods['licenca'] 	     = 'Licença do criador';
	return $contactmethods; 
}





















function cria_usuario($user_login,$user_nice_name,$user_pass,$user_email,$user_display_name,$user_nickname,$user_first_name,$user_last_name,$user_role,$user_registered){
	$user_data = array();
	$user_data["user_pass"] = $user_pass;
	$user_data["user_login"] = $user_login;
	$user_data["user_nicename"] = $user_nice_name;
	$user_data["user_email"] = $user_email;
	$user_data["display_name"] = $user_display_name;
	$user_data["nickname"] = $user_nickname;
	$user_data["first_name"] = $user_first_name;
	$user_data["last_name"] = $user_last_name;
	$user_data["role"] = $user_role;
	$user_data["user_registered"] = $user_registered;
	return  wp_insert_user( $user_data );
}

function insere_usuario_meta($user_id, $telefone, $fax, $morada, $codigo_postal, $concelho, $localidade, $stam, $especies, $clube, $clube2, $clube3, $licenca) {
	$add_user_metadata = array();
	$add_user_metadata["telefone"] = $user_pass;
	$add_user_metadata["fax"] = $user_login;
	$add_user_metadata["morada"] = $user_nice_name;
	$add_user_metadata["codigo_postal"] = $user_email;
	$add_user_metadata["concelho"] = $user_display_name;
	$add_user_metadata["localidade"] = $user_nickname;
	$add_user_metadata["stam"] = $user_first_name;
	$add_user_metadata["especies"] = $user_last_name;
	$add_user_metadata["clube"] = $user_role;
	$add_user_metadata["clube2"] = $user_registered;
	$add_user_metadata["clube3"] = $user_nickname;
	$add_user_metadata["licenca"] = $user_registered;
	return  add_user_meta( $add_user_metadata );





return add_user_meta( $user_id, 'campo', $valor);

}



function get_category_id($cat_name){
	$term = get_term_by('name', $cat_name, 'category');
	return $term->term_id;
}












?>